


#import "UIButton+Extension.h"

@implementation UIButton (Extension)

////  根据图片设置默认和点击图
///
///  @param title     title
///  @param imageName imageName
///
///  @return UIButton
- (instancetype)initWithTitle:(NSString *)title ImageName:(NSString *)imageName {
    if (self = [super init]) {
       
        // 设置图片
       NSString *imageNameNor = [NSString stringWithFormat:@"%@_normal",imageName];
        [self setImage:[UIImage imageNamed:imageNameNor] forState:UIControlStateNormal];
        // 选中图
        NSString *imageNameHig = [NSString stringWithFormat:@"%@_highlight",imageName];
        [self setImage:[UIImage imageNamed:imageNameHig] forState:UIControlStateSelected];
        // 标题
        [self setTitle:title forState:UIControlStateNormal];
        // 标题字体
        self.titleLabel.font = [UIFont systemFontOfSize:14];
        // 字体颜色
        [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    return self;
}
/**
 * 根据title 和 Num 设置 Num在上 title在下的格式
 */
- (void)setTitle:(NSString *)title Nun:(int)num {
   
    NSString *str = [NSString stringWithFormat:@"%zd\n%@",num,title];
    [self setTitle:str forState:UIControlStateNormal];
    self.titleLabel.numberOfLines = 0;
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self setTitleColor:[[UIColor alloc] initWithRed:63 / 255.0 green:156 / 255.0 blue:157 / 255.0 alpha:1.0] forState:UIControlStateSelected];
    
}

@end
